package com.hsource.doctorcenter.service.order.impl;

import com.alibaba.fastjson.JSONObject;
import com.hsource.doctorcenter.domain.order.Order;
import com.hsource.doctorcenter.service.api.IApiService;
import com.hsource.doctorcenter.service.order.IOrderService;
import com.hsource.doctorcenter.util.SpringUtils;
import lombok.extern.slf4j.Slf4j;

import java.security.NoSuchAlgorithmException;
import java.text.ParseException;

/**
 * @author yangYang
 * @version 1.0
 * @date 2020/9/30 13:40
 * @describe 快捷电话服务业务逻辑
 */
@Slf4j
public class QuickCallServiceImpl {

    /**
     * 开通服务
     * @param order
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     */
    public void openingService(Order order) throws ParseException, NoSuchAlgorithmException {
        IApiService apiService = SpringUtils.getBean(IApiService.class);
        IOrderService orderService = SpringUtils.getBean(IOrderService.class);

        String paidProblemString = apiService.createFastPhone(order.getUserId(), order.getContent(), order.getClinicNo(), order.getId(), order.getPhone());
        log.info("=====================QuickCallServiceImpl=服务======"+paidProblemString);
        JSONObject jsonObject = JSONObject.parseObject(paidProblemString);
        if(jsonObject.get("error").toString().equals("0")){
            Order o=new Order();
            o.setId(order.getId());
            o.setProblemId(jsonObject.getInteger("service_id"));
            orderService.updateOrder(o);
        }
    }
}
